Remove code duplication.
Improve documentation.