added check for keyboard interrupt