Fix bisection a lot and add tests for it