fixed some scope issues