Add documentation and improve logging messages.