tidy up javascript