Refactor swapOnDragUpdate function