Add some defensive checks before casting.
Merge pull request #4 from csmith/defensive-checks

Add some defensive checks before casting.