cleanup for jshint, add comments, add TODO notes, fix minor syntax and logic bugs