Added some output statistics
Some refactoring