Fix infinite loop stated in #9