Added more error checking to camera code