Boring graph stuff (doesn't handle cycles yet)