Fixing graceful termination