Final working version of the simulation