Fixed problematic tests.
Refactored stats gathering.