[cg_level] duplicated code turned into function