Minor refactoring and commenting.