Refactor js code.