Tidy up some code