Cleaned up some memory leaks on close