Add method doc. Minor refactorings.