added thread and socket stuff