Simulation Working code