minor refactoring, added some documentation