start refactoring client side javascript