graph building reworked