added check for NAs in input matrices