fixed a bug in the defrag method