Some minor refactoring and commenting.