fixed a bug on the simulation algoritm