updaated to handle simulation and generate statistics