Tidy up and remove old code