proper scoping of variables