tidy up and make a bit more efficient