In MD.cpp line 319 it should be -= instead of += to make it equivalent to the commented out code above. It is totally my fault but I'll submit the issue to you anyways. I blame tiredness -_-
You also need to redo the j=0; after line 220 that ArnaudFiorini pointed out.