First cut at toposort