A rewrite of the javascript