minor adjustments and removal of code that just doesn't need to be there. Additionally added a bunch of debug console.log() for unit testing purposes.