rewrite client side javascript code