Refactored Main.java