BUG fix: the algorithm is now consistent even with collisions in hash