Fixed problem with function variable scopes.