Working code for camera thread