issue #30
 minor refactoring and cleanup