Finished Java version