Fixed logic for input handling.