merge deallocate and defragment functions