Moved result formatting to separate function