Small refactor to handle gracefull shut down on SIGINT and SIGTERM