faster findlengths method