pair wise optimization bug fix