Bingo, 24 = afm temp sensor, so I'd check the AFM connector for stiff, frayed wires, and go from there.
51 is tps, or ac if the AC was on during the check...
TPS means there was nop idle contact during the diagnostic check, have you replaced the tps lately?