Move some methods out of Graph
Fix an issue with some loops