Included Duncan's pair counting code