Binary search seems to work, but it need some fixes