Fixed infinite loop