Added some signal handling so the program exits more appropriately