Modified to work with keyboard input.