Merged changes from CDI branch
Fixed merge (unit tests now pass)
Updated dependency sorter to actually work correctly in more complicated cases