Fixed some error handling in the Trace class.
`trace.kill` was throwing NullPointerExceptions if called before `trace.start`. A conditional was backwards, resulting in its code never being called (to kill the trace upon encountering a fatal error before starting). I also added do-once guards on a couple of the shutdown-related tasks.