fix edge case where consecutive pairs have same key, core algorithm now runs