Tweaked heuristic function