added a heuristic that makes greedy search perform near optimal