Added graceful shutdown
fixes #47