added graph construction (not very well)