Working on threading, connection, etc.

There's a bug in one of the loops now, but I figure I should
commit before I get much further.