Cleaned up the signal-handling code a bit