Fix infinite loop. Related to issue #78