Refactor JS