bug fix for loops without exit