starting to rewrite the javascript