refactor JS