Start adding support for proper simulation shutdown.
Fix simulation shutdown (issue #22).