Now uses threads

Fixes a number of bugs, including the inability to connect to remote hosts