completed calculateHandLen function