Fix dynamic scoping caching issue