Add tests and fix for duplicates