Refactored minimize functionality for document.toObject, improves performance