Adding graceful exit functionality.