Improve Graph object creation function.