refactored code, js according to jslint