optimization in searching intervals