Client-side js refactoring