Fix bug preventing deleting the last image. Fixes #46

See the discussion on issue #46 (I can't add the PR to the issue since
I'm not the issue owner).