tidying the javascript a little