Remove some extra duplicated code and group the equalities and hash code tests together