Adds support for distinct operation.

Unfortunately I haven't been able to write tests because I have been running
into an error. 

Any help writing tests would be appreciated