Consider doing this recursively.