refactor stat generation in only one file