updated binarysearch so that it doesn't loop forever when it doesn't find a match