-fixed local varible scope issues