Working out some issues with local scope