variable scope error fixed