Added a topological sorting algorithm from http://www.logarithmic.net/pfh/blog/01208083168
Implemented running tasks in stages, with topological ordering of stages and tasks