Completed refactor js