Refactoring dagification -- still needs work.