Fix lowerBound issues and add tests for it. Now it matches C++'s lower_bound.