Move graph code into own file