handle zeros properly in extractPairs