change length->size and check loop ranges