More refactoring. Added statistics