old simulation code