improvements proposed by code review by mvidner