integrated Klaus's fixes