Fix looping conditions