Minor refactoring of javascript