Fixed a lot of bugs related to the client/server communication.

Also implemented a multi-threaded version of the server