Moved graph implementation to inner class.