fixed defragment_memory function more