Minor refactoring to js file