TODO: Minor bug fix in Java implementation.