Add statistics test with some coverage. Fix bugs in Stats implementation.