Fixed weird drag-to-sort bug

Simplified the code in the process.