bug fixes in range iteration