modified main.java to be more understandable