Another refactor to make doLookup smaller