[UPDATE] reimplement with binsearch module. Include tests.
[FIX] tests.