Fix bug with moving segments to the beginning of the document