Re-apply missing null check from Bruno Oliveira

Reapplies the fix from commit e7b3758, which was mistakenly removed in 81ff43c. Fixes #60.