Tidy up javascript