Java: Functions redesign