Compute length in separate function