check for nil in ensure part
Merge pull request #347 from peter-x/patch-1

check for nil in ensure part