Work around non-support of distinct by handling unique in memory

See: http://stackoverflow.com/a/13265802/110740