a few JS refactorings