tidy up the code a bit