Added graceful shutdown