refact code in search rotated array