JS refactor