final fix to memory management