Fix dynamic scoping issues