implements unique algorithm

this is ugly :/