Apply DRY seriously: code base has too much duplicated code blocks. Add missing doc comments for not trivial stuff.