I did some code linting on the file

Moved variable declarations to top of scope, and combined into one statement. Added semicolons to end of statements. Changed == to ===