Profile deletion, top-level section modification bugs

Neng closed pull request #163, so I'm opening one for my branch.  The first two commits fix bugs; the third adds tests.