Add safety net against potential infinite loop