Reworked server code:

* Unified server and client way of handling communication
* Better handling of client exiting