main: move statistics related code to stats module (close #87)