Limit the number of loops, when writing. Pull request #783.