refactored adding of vertices to graph