Add tests and simplify Stat function