Fix bug in heuristic functions