Moves thread handling into device.c