[cg_level] another piece of duplicated code turned into function