Fixed scoping issues