optimized matrix_form