Fixed a small bug in MetricsListener, fixed the tests.