Significantly simplified the api path matching code.