Fixing possible infinite loop