improved heuristic for middle stage