fix infinite loop (thanks to Kevin Chiu / KevinC1118, see Pull Request #3)