graceful shutdown and support for multiple instances