Fix scoping issues