Fixed a bug in the previous fix.

The length sanity check for new settings can only work if the header is already written. Due to the changed order of operations in the previous commit, we also need to move the check further down.