Fix js style, run through JSHint and fix undefined variables