refied the heuristic so that it works better