tidying up javascript