Fix variable scope