Working algorithm without wars