fix deallocation bug