added incremental counter to next to prevent infinite loop
Merge pull request #6 from croucha/master

added incremental counter to next to prevent infinite loop