Fix bad variable scope