Changing samples in the zone

This method works really well. However I am trying to implement a fix for the loop. The sample length is changed when the sample is changed but the loop range/end still keeps the previous length. Is it possible to update the loop range or even just send the sample length of the new sample to the loop parameters?