cleaned up and fixed some bugs in the binary search.. for some reason I thought I tested this. Added a unit-test for it.