Added original Java implementation.