Complete refactoring of the graph based branch. Lost many comments in the process...