Corrected for memory leaks.