Handle Ctrl-D and Ctrl-C