Exercise 3 finished. New simulate function improved.