minor refactoring of javascript