Fixed the infinite loop bug.. Current heuristics are worse than naive solt