fix loop ranges