Starting moving functions out of graph class

Make them pure and easily testable