fixed memory leak in new code.