Fixed infinite loop bug.