Substantial JS refactoring and cleanup as per JSHint. Correcting of missing closures, semicolons, and re-declared variables.
Merge pull request #219 from jvc26/jshint-cleanup

Big JSHint based cleanup