Improve documentation and refactor.