Bug fixes for statistics