Fixed infinite loop error