simulation script rewritten