Nifty stays range-bound near 23,800; small, midcaps lead rally