bug fix + additional logic for checking pairs