Cleanup logging and make stopping more graceful.