fix topsort order + add a bit of tests