Some optimization for the simulation algorithm