either signal causes the main thread to be cancelled. added necessary code to make main thread cancellation clean up nicely.