Logical error in heuristic fixed