rewrite stats recording and analysis