Finished the Java version