rewrote whole logic of segment and fragment number detection