fix graceful shutdown