rewrite in plain js