Added generics to Pair class and fixed hashcode problems.