remove main object globals and instantiant them where they are actually used