More refactoring to address comments.