moved reformatting into separate function