Kameda-Weiner algorithm is implemented. Some additional refactoring.