More properly handle shutdown