Tidy up the javascript