Fixed some segfaults and made all connections nonblocking.