reorganized deallocate functions.