Rewrite algorithm to build the module chain according to module's position hints.

The previous algorithm was attempting to make a deterministic sort, which is not applicable here because there is no notion of strict ordering.
The new algorithm works in a way similar to a search of dependency.
in 43 minutes and 49 seconds and was queued for 4 seconds
latest