Added support for handling ctrl+c events. Also added some printf() debugging code.