building equivalence classes