added min diag function