Added Try-Catch statements around Integer.parseInt() usage, to handle exceptions gracefully