reorganized simulation saving/restoring code