improve mcgbGenerate algorithm