Handle termination and clean up

Fixes error messages being printed on ^C.