updated code for drag and drop and sorting