Avoid infinite recursions

Closes #60

Thanks to Lennart Regebro for the bug report and initial attempt at a
patch.