some improvements in flatten and addition of TqVsR argument