trying to clean up memory leaks, causing crash