pull stat calculation into a function