cleanup CG code
remove non-ISO C functions dependency