Many fixes to signal handling.

Still need to come up with something for handling SIGTERM and wait.