fix bug for ClosePair function