Add diag and sum functions