rewrite in vanilla javascript