js refactor