factor out the javascript code into another file