Ensured input is always deduplicated and ordered; added tests for this.