Refactored rendering and dragging code