minor refactoring; documentation improved