UNTESTED: proposed fix for memory leak problem.