Rewrite in vanilla JS