Added proper variable scope