tracing to understand what's wrong with variable lookup inside a funciton