Improve some internal names and scoping issues