replaced own implementation with bisect