Bugfix: prevent invalid comparisons when building statistics