removing the header of the sections with no elements and ordering the elements of each section everytime they change