Cleaned up some scoping issues