optimize the heuristic computation(recursion), add timeout detection.