improve stack frame + add global vars