added rdocs and small refactoring