corrected memory cleanup