More refactoring for consistency and reuse as a library downstream.