cleanup matrix