Assorted fixes

Adhere to styleguide:
  - Add spaces after keywords
  - Add spaces after opening brackets
  - Add spaces before closing brackets
  - Add semicolons where missing

Remove newlines from difficult to read multi-line if statements

JSLint:
  - Use `===` and `!==` to compare `null`
  - Add `var` to `for()` loops
  - Remove redundant `var` calls
  - Use dot notation on objects where appropriate