added a keyboard handler, and fixed the iostream issue