Document processing algorithms