Implement reorder function