fixing deallocation bug