Implement signal handlers and improve logging.