Some refactoring and docs.