fixed memory deallocation problem