Handle ctrl-c and ctrl-d properly