Tidying up javascript