Created wrapper for SocketIO communication.
Moved cleanup to the right place