moved caching earlier, minor comment changes