super minimal topsort implementation