Fix for duplicate callback bug, issues #16 and #29

As discussed in issue #16, this fixes an issue where the callback can be called twice upon error. There's an example image that causes this in issue #29. I have tested this and verified that it fixes the issue as I described it in #29.