Updated heuristic function