Move ref path matching to connect.c library