Moved relation lookup and relation match logic into non-task API.