Fixed some scope issues