Changes to prevent Soql limit from being hit.