Fix some scoping issues