some optimizations to graph