corrected the insertMemory function