Fixed some memeory leaks.