template fill caching and other fixes