Applied patch by Adam Chlipala adding comments and minor refactoring