Refactored code to reduce latency to triggering the photo.