tidying up and optimising