Adding fixes from bugs found doing initial java implementation