Document and finish up some refactoring