Refactoring after testing against jslint