Refactor stats calculation -> stats.py