Added possibility of setup/shutdown logic; removed return-to-exit rewrite; fixes.