Heuristic fixed. with proper distance computation and return 0 when all ...

...gems cleared.