updated pairwise with zoch's fast method for building X