Refactor, document, clean up.