Fixed memory issue,working statistics and tests