fixed a small bug with length summation