added working d_mat_gso and other helper functions