nested function scoping issues