Fixes thread problems and set socket timeout of 30 seconds.