Rename write to arrange.
Tidy up code.
Add more tests.