Unreverting the revert of statistics with memory leak, fixing the bug

that caused the memory leak, added a few unit tests, version bump