Fixed a bug that sometimes made write chunks in the region file header.

This bug was introduced by me in the last commit. The pull request also makes the header info to update itself after every region modification.