adding writing images and optimize exception handling for the ProcessImage class