Cleaned up potential memory leaks.