Added model caching, which seems to work OK.