refactoring dragging code