big merge, added globals  and scal