Implementing topological ordering for this->versions before cleaning.