Refactor and fix documentation.