Refactor out the matchRole function