Refactoring javascript due to jshint