Corrected implementation of heuristic.