takeLength function