fixed iteration of heuristic. Wrong ordering between operatands in the outer condition