rewrite js code