added handling of SIGINT and SIGTERM