refactoed Main.java