Implement sanity check

Untested but should work. Fixes #1