added caching to Templates and fixed else statements