add logic to throw error when unexpected nil received

Fixes #105