Swap defer with nil guard to avoid nil reference
Merge pull request #21 from jpfielding/nil_reference

Swap defer with nil guard to avoid nil reference