Added debug information. Fixed several bugs in the reconstruct loop function.