minor refactoring and doc strings