JS rewrite