Documentation and matching optimization

Documenting code for presentation to Centosette, as well as tidying some
things up that needed it.