Fixed duplicate and added sorting

Fixed the duplicate issue between groups and added code to sort elements
in a group after the drop has occurred.