Tidy up some memory issues