Removed trailing white spaces and refactored stats accumulation.