Updated version of bsearch.cpp