refactoring of client side js