Fixed some memory leaks. Still more need to be cleaned up.