improve uniq-ifying algorithm to use IDs rather than object identity