Minor JS refactoring