Allow changing between temporary store and database. Fix linear iteration when facts have multiple references.