Finish js rewrite