Added method to get equivalence classes of substitutions, and updated out_handler to make use of it.