completed sampling and updating steps and combined everything into a function called simulation