Main simulation loop