convert_to_mat bug fixes