Rewrite remaining JavaScript