Fixed infinite loop issue