refined heuristic function