consolidate same_or_different into one function