Gracefully shutdown event loop, closes #346