Rewrite js codes