Improved the try catch for input