Handle shutdown better