client js cleanup and refactoring