actually fixed the diag function