fix gcc warning
clean up binary search code
change midpoint calculation