Fix variable scope error