Improve check for nested writes
Merge pull request #2266 from tomchristie/improve-nested-write-checking

Improve error checking for nested writes.