Dynamic programming fix

Sorry, committed loads of gibberish before