added modified cg_sim.c