jslint fixes, refactoring