first pass of the main algorithm + section creation