partial refactoring for issue #4