fixing count issue in simulation.c