updates matrix and nj trees