Transform dependency graph depth-first; fixes #423