refactor statistics out of main and into library part.