Refactoring aligned with diagram on GitHub wiki.