Refactored deduplicate (with array), fixed tests.