fixed scoping code