Fixed bug with scoping