rewrite javascript