Working, deals badly with bigger size.
wip
Efficient algorithm.
Retain path nformation.