Added recording of stats and some more tests.