nicer code, caching, and some history fixes