Adapt mvidner's suggestions.