Fixed code for running simulations