refactoring to use plain functions to do the lookup.