Refactored some code and style for jslint