Implement 'dirty bit' logic

Also do some other changes important for this---see the commit messages for the first two commits
can you put the call to headnode.delete() here? it might fail a test at first, but will work fine once #170 is merged in.