Added optimization to remove unecessary comparisons in Treeset