minor refactoring in js