subtle JS refactor