externalize stats calculation