Issue #40: a bit of refactoring