Changed declarations of caches to use var. Found experimentally to be faster.