Updated debug output and fixed some minor bugs in code.