working on memory cleanup code