Adding signal handling and debug mode