Minor refactoring to the js