Change diag function to return results instead of printing