corrected mistake and defined bsearch