Added cleanup handler for ctrl-c and Windows terminal closing