It now gives the best path and gives the correct dependencies
Fixed bug in em algo. Added asserts