making stuff exit cleanly when things go wrong