fix length calculation.
fix bug with length, add timing.