Beam folding analysis and optimization of mask-enhanced toroidal multipass cells