Add debug statements, corrected minor bugs