refactor the js