some documentation and small refactoring.