Added error check in process image loop