Did a pass with jshint and cleaned up the code a bit.