some bugs related to use_cache, etc.  also a lot of cleanup.