Re-define buildmatrix