Graph based

If anyone can double-check this and merge it that'd be great. KTHXBYE