added plotImage
error handling updated