Bugfixes to stats calculation