rewrite using pure javascript

as described :)