common JS refactor