Added fix to avoid infinite loop eating resources