Potential Py bug, fixed
Initial Java version