Tidy up the structure of the drag and drop code