Reworked template handling and caching, added history, reworked session/login path to use the API.