Fix bugs and add unit tests for BSEARCH()