Tidy up the code a bit