Use proper function scoping