Add statistics and refactoring