fixing some matrix stack logic