fixed some bugs in the statistics functions