Implement 'dirty bit' logic

Also do some other changes important for this---see the commit messages for the first two commits
Maybe add nullable=False?