diff --git a/R/lauricella.R b/R/lauricella.R
index 9c45b46d8aad0f6b1c42bf054ef13388a0316808..c18fc2fedb356381df03231926161657e3129545 100644
--- a/R/lauricella.R
+++ b/R/lauricella.R
@@ -81,15 +81,18 @@ lauricella <- function(a, b, g, x, eps = 1e-06) {
   
   # Logarithm of the product m_1! * ... * m_n! for m_1 = 0...k, ...,  m_n = 0...k
   # i.e. \sum_{i=0}^n{\log{m_i!}}
+  # lnfact <- as.data.frame(
+  #   matrix(sapply(Munique, lnfactorial), nrow = length(Munique),
+  #          ncol = n, byrow = FALSE, dimnames = list(Munique, 1:n)))
   lnfact <- as.data.frame(
-    matrix(sapply(Munique, lnfactorial), nrow = length(Munique),
+    matrix(lfactorial(Munique), nrow = length(Munique),
            ncol = n, byrow = FALSE, dimnames = list(Munique, 1:n)))
   # sumlnfact <- function(ind) {
   #   # sum(mapply(function(i, j) lnfact[i, j], ind+1, 1:n))
   #   sum(access(ind, lnfact))
   # }
   # Table of all combinations of the log(m_i)
-  gridlnfact <- expand.grid(as.data.frame(lnfact))
+  gridlnfact <- expand.grid(lnfact)
   # Sum of the logarithms
   sumlnfact <- rowSums(gridlnfact)