JShint fixes and refactoring.