optimize local-fetch by moving things out of the loop