Issue #167: refactored some common code