Js refactor