Fix infinite loop

Solves #4