Some more code refactoring to handle stat