Java port
Minor reformatting