Fix segment number calculation