fixed several scope issues