refactor java builder; bug fix