Simplified code and changed \diag command