Corrected variable scopes.