calculating total length