adds threading code