enhance the assert that l < mid < r