auto pair function