Modified threading for the connection
- created own classes for the threads
- implemented proper locking and proper queues.