Updated to use each_pair