More comments and minor refactoring.