Fix infinite loop

Fixes #21