Stats refactor

Split drawtime/srcbytes stat handling + cookie encoding into its own lib with tests.