fix length calculation