Applied fix for potential infinite loop