More refactoring and commenting.