added binary search for calculating the frame number.