Avoid explosions (code a little different from PR)

Closes #11