Improved shutdown method (no more experimental signal handling, now via shutdownhook)