Issue #167: some cleanups and small logical improvements.