tidied up graph building