slight refactoring from PR #153