tidying up and commenting js