Move simulation code to separate file for testing.