Moved code for getting the dependency tree into a new Tree module

This will allow it to be shared with the GUI.