Edits to deal with memory leaks.