refactor variable name lookup into a separate function