Added locking around factories dictionary