remove duplicated code and ambiguous Java methods