debugged deleteMem function