fix imagick builds using wrong version
clean up and simplify some error handling