Fix exception in stats with empty database