Simplified implementation of Graph class.