Improve performance when failing.

Refs #2.
Add test for empty hash.

Refs #2.