Biodiversity as spatial insurance: the effects of habitat fragmentation and dispersal on ecosystem functioning