Refactor to java