Some more modularity and tests.
Example for #163.