refactor java code