Js refactoring