Refactor and simplify drag/drop/insert logic