Updated code to remove some duplicates .