Tidy code and fix comments

The configuration section was not organised. Moved lines around so they
are grouped with similar tasks.