Fixed infinite loop bug 2