minor bugfixes with token replacement hook and metrics caching.