Fix bug preventing deleting the last image. Fixes #46

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