Add signal handling and logging on termination