Moved exit logic out of exec and into lib