cleaned up some memory management