diff --git a/99_HIDDEN_functions.R b/99_HIDDEN_functions.R
index c5c919adcbc87ea4cbcb36548e62a4adea779ad8..0c4da102c4541c5de23c3dd7003fd819000057df 100644
--- a/99_HIDDEN_functions.R
+++ b/99_HIDDEN_functions.R
@@ -37,7 +37,7 @@ get.corXY.bootstrap <- function(comm, traits, trait.sel="all", bootstrap=199){
   ## CAUTION - function below doesn't work as expected
 #  binary.traits <- which(apply(traits[,ii,drop=F], MARGIN=2, function(x)( all(na.omit(x) %in% 0:1) ))==T)
   
-  syn.out.tmp <- matrix.x(comm=comm, traits=traits[,ii,drop=F], scale=T)$matrix.X #, asym.bin=binary.traits
+  syn.out.tmp <- SYNCSA::matrix.x(comm=comm, traits=traits[,ii,drop=F], scale=T)$matrix.X #, asym.bin=binary.traits
   W.beals <- as.data.frame(beals(comm, include=T, type=2))
   # permute traits 
   ### Create vector of species to resample from, which exclude species with NAs
@@ -107,6 +107,7 @@ matrix.x <- function (comm, traits, scale = TRUE, ranks = TRUE, ord, notificatio
       warning("Warning: NA in community data", call. = FALSE)
     }
   }
+  #x.all.NA <- apply(traits, 1, function(x){!sum(is.na(x))==0})
   x.NA <- apply(traits, 2, is.na)
   if (notification) {
     if (any(x.NA)) {
@@ -134,6 +135,16 @@ matrix.x <- function (comm, traits, scale = TRUE, ranks = TRUE, ord, notificatio
       warning("Warning: NA in matrix U", call. = FALSE)
     }
   }
+  ## re-standardize matrix.w, replace abundance of species which have no trait information with 0
+  u.all.NA <- which(rowSums(is.na(matrix.u))==ncol(matrix.u))
+  if (notification) {
+    if (length(u.all.NA)>0) {
+      warning("Warning: For species without trait information, replace the abundance with 0 in matrix.w, and re-standardize by plot totals", call. = FALSE)
+    }
+  }
+  matrix.w[,u.all.NA] <- 0
+  matrix.w <- sweep(matrix.w, 1, rowSums(matrix.w), "/")
+  
   matrix.u[u.NA] <- 0  
   matrix.X <- matrix.w %*% matrix.u
   matrix.X <- sweep(matrix.X, 1, rowSums(matrix.X), "/")  ## RE-SCALE to avoid problems propagating from NAs