fix calculating dynamic lengths