New version of the javascript and a lot of tidying up