Added new code to sort and remove duplicates entries