factory/cache improved, now thread-safe