Fix unit test, and better sanity checking