added checking for valid pair ids