Refactor and fix jshint