Refactor for readability.
Add docs.