debug.js bug fixes

There were a few minor bugs in the debug.js file that was causing it to crash.