Add .jshintrc and refactor js code