Further improvements based on Steven's fixes.