refactored out GraphBuilder and added a test for it
refactored out GraphBuilder and added a test for it