refactor in Pair.scala