Use topsorted array instead of recursion in rendering