Minor rewrite and cleanup of local cache