Refactor js