Variable scope issue