Modified to avoid too many functions or groups set when contributing a document.