More cleanup and refactoring.

Now most functions are stable. tomb open -k image.jpg can use images
directly as keys, works on tests, but needs more debugging.