Nested function to remove most globals