Better implementation of Graph