updated java implementation