removed unnecessary check
reordered code
support to use pair as where's key