Avoid sometimes infinite loop
Merge pull request #9 from tyx/fix/infinite-loop

Avoid sometimes infinite loop