Minor refactoring, documentation for some methods added.