rewrite in js