added handling of KeyboardInterrupt exception