Starting to remove System.exit() in the code