add isValidPair check and remove excess logging