Improved input. Handled NumberFormatException.