stat and statbuff refactor