switch type length calculation to a less brittle solution