diff --git a/CustomModels/channelmodel.cpp b/CustomModels/channelmodel.cpp
index d9cc7510d413ca5e7360953b9970ec852ca5c10f..419d8ceb5c74a8dcae8ba7f6f5718f6550dc3613 100644
--- a/CustomModels/channelmodel.cpp
+++ b/CustomModels/channelmodel.cpp
@@ -7,7 +7,8 @@ ChannelModel::ChannelModel()
 
 int ChannelModel::rowCount(const QModelIndex &parent) const
 {
-    return channelList.count();
+    int count =channelList.count();
+    return count;
 }
 
 QVariant ChannelModel::data(const QModelIndex &index, int role) const
@@ -159,3 +160,11 @@ void ChannelModel::sortChanged()
     endResetModel();
     emit countChanged();
 }
+
+void ChannelModel::clear()
+{
+    beginResetModel();
+    channelList.clear();
+    duplicateCheck.clear();
+    endResetModel();
+}
diff --git a/CustomModels/channelmodel.h b/CustomModels/channelmodel.h
index 0ed671446fdcbe5e1763a75b6522658531122663..67436c0ac43ba8338ae6ffe75ed879f0ef772aa7 100644
--- a/CustomModels/channelmodel.h
+++ b/CustomModels/channelmodel.h
@@ -34,6 +34,7 @@ public:
     QString getType() const;
     void setType(const QString &value);
     void sortChanged(void);
+    void clear(void);
 protected:
     SortedVector<RocketChatChannel> channelList;
     QSet<QString> duplicateCheck;
diff --git a/api/meteorddp.cpp b/api/meteorddp.cpp
index ba9d135d5c472e1c02065dd54fffb1ce9f4aaff1..9b60ddbe14e0e52d25adabd9b51170a3b69d5711 100755
--- a/api/meteorddp.cpp
+++ b/api/meteorddp.cpp
@@ -8,7 +8,7 @@
 #include <functional>
 #include "ddpRequests/ddploginrequest.h"
 
-MeteorDDP::MeteorDDP( QString pUri )
+MeteorDDP::MeteorDDP(QObject *parent, QString pUri ): QObject(parent)
 {
     mError = new QJsonParseError;
     init( pUri );
@@ -17,7 +17,7 @@ MeteorDDP::MeteorDDP( QString pUri )
 
 void MeteorDDP::init( QString pUri )
 {
-    mWsClient = new Websocket;
+    mWsClient = new Websocket(this);
     QUrl wsUri = QUrl( "wss://" + pUri + "/websocket" );
     qDebug() << wsUri;
     qDebug( "meteor init" );
diff --git a/api/meteorddp.h b/api/meteorddp.h
index 2290efd1dee439312a1b206299cfdf248ab17a16..0692e4b8a65a5fe218a371e24d12a66e8006fd50 100755
--- a/api/meteorddp.h
+++ b/api/meteorddp.h
@@ -19,7 +19,7 @@ class MeteorDDP : public QObject
 {
         Q_OBJECT
     public:
-        MeteorDDP( QString pUri );
+        MeteorDDP( QObject *parent, QString pUri );
         void connectWithServer();
         ~MeteorDDP();
         QString getToken() const;
diff --git a/api/restapi.cpp b/api/restapi.cpp
index 2fd1b71e8240c88210e8aefe4cfa89ecf36c19ad..d4efd7f2df04541f834e83177bfbdd80263ebbb0 100755
--- a/api/restapi.cpp
+++ b/api/restapi.cpp
@@ -1,16 +1,7 @@
 
 #include "restapi.h"
 
-
-RestApi::RestApi()
-{
-    mApiUri = "https://test.ucom.gv.at/api/v1";
-    mBaseUrl = "https://test.ucom.gv.at";
-    qRegisterMetaType<RestApiRequest>("RestApiRequest");
-    init();
-}
-
-RestApi::RestApi( QString pBaseUrl, QString pApiUri ) :  mApiUri( pApiUri ), mBaseUrl( pBaseUrl )
+RestApi::RestApi( QObject *parent,QString pBaseUrl, QString pApiUri ) :  mApiUri( pApiUri ), mBaseUrl( pBaseUrl ), QObject(parent)
 {
     qRegisterMetaType<RestApiRequest>("RestApiRequest");
     init();
diff --git a/api/restapi.h b/api/restapi.h
index 30967a4b0e56a1b9d6eb2dd3a29a6fb055085048..87b3902514072ce2891f0dbba217b7a712fb2669 100755
--- a/api/restapi.h
+++ b/api/restapi.h
@@ -34,8 +34,7 @@ class RestApi: public QObject
         Q_OBJECT
 
     public:
-        RestApi();
-        RestApi( QString pBaseUrl, QString pApiUri );
+        RestApi(QObject *parent, QString pBaseUrl, QString pApiUri );
         void login( QString pUsername, QString pPassword );
         void logout();
         QString getName() const;
diff --git a/engine.pro b/engine.pro
index 65592773f641fbc4400e31c5a441edf8c4e64a63..efa6e76082e798758b3cc1403f14d8937a1b4e38 100644
--- a/engine.pro
+++ b/engine.pro
@@ -228,7 +228,7 @@ CONFIG(release, debug|release) {
     CONFIG  += qt release
     DEFINES += QT_NO_DEBUG_OUTPUT
     DEFINES += QT_NO_DEBUG
-    CONFIG += ltcg
+    #CONFIG += ltcg
     # compiler options: O3 optimize
     linux:{
          QMAKE_CXXFLAGS += -O3
diff --git a/rocketchat.cpp b/rocketchat.cpp
index 832bae117c8302ac773c8a71ec4a0b502fd0dd3c..9dafb73ef1b8259f40b2765b95b834a645eec675 100755
--- a/rocketchat.cpp
+++ b/rocketchat.cpp
@@ -28,7 +28,8 @@
  * @param restApi
  * @param ddp
  */
-RocketChat::RocketChat( QGuiApplication *app )
+RocketChat::RocketChat( QGuiApplication *app, ChannelModel &channelModel, ChannelModel &groupsModel, ChannelModel &directmodel, MessagesModel &messagesModel, UserModel &userModel )
+    : channelModel( channelModel ), groupsModel( groupsModel ), directmodel( directmodel ), userModel( userModel ), messagesModel( messagesModel )
 {
 #ifdef Q_OS_IOS
     UrlHandler *handler = new UrlHandler;
@@ -36,8 +37,8 @@ RocketChat::RocketChat( QGuiApplication *app )
     // connect(handler,&UrlHandler::openFile,this,&RocketChat::openIosFile);
 
     mShareHelper = ShareHelperSingelton::getInstance();
-        connect( mShareHelper, &ShareHelperSingelton::shareLinkReceived, this, &RocketChat::openIosFile, Qt::UniqueConnection );
-  
+    connect( mShareHelper, &ShareHelperSingelton::shareLinkReceived, this, &RocketChat::openIosFile, Qt::UniqueConnection );
+
 #endif
     this->mApp = app;
     connect( app, &QGuiApplication::applicationStateChanged, this, &RocketChat::onApplicationStateChanged, Qt::UniqueConnection );
@@ -51,13 +52,13 @@ RocketChat::RocketChat( QGuiApplication *app )
     //KeypadHelper *helper = new KeypadHelper();
     //helper->showKeypad();
     mInputMethod = QGuiApplication::inputMethod();
-    connect(mInputMethod,&QInputMethod::visibleChanged,this,&RocketChat::onKeyboardVisiblityChanged);
+    connect( mInputMethod, &QInputMethod::visibleChanged, this, &RocketChat::onKeyboardVisiblityChanged );
 #endif
 #ifdef Q_OS_ANDROID
     mAndroidStatusBarColor = new AndroidStatusBarColor;
 #endif
-    qRegisterMetaType<ConnectionState>("ConnectionState");
-    qRegisterMetaType<Qt::ApplicationState>("Qt::ApplicationState");
+    qRegisterMetaType<ConnectionState>( "ConnectionState" );
+    qRegisterMetaType<Qt::ApplicationState>( "Qt::ApplicationState" );
 }
 
 RocketChat::~RocketChat()
@@ -72,9 +73,10 @@ RocketChat::~RocketChat()
 void RocketChat::joinChannel( QString pServerId, QString pChannelId )
 {
     Q_UNUSED( pServerId );
-    if(mServerStatus){
 
-        QMetaObject::invokeMethod( mServerMap.first().data(), "joinChannel",Q_ARG( QString, pChannelId ) );
+    if ( mServerStatus ) {
+
+        QMetaObject::invokeMethod( mServerMap.first().data(), "joinChannel", Q_ARG( QString, pChannelId ) );
     }
 }
 
@@ -85,15 +87,17 @@ void RocketChat::login( QString pServerId, QString pUsername, QString pPassword
     if ( pUsername != mStorage->getUserName() ) {
         mStorage->wipeDb();
     }
-    qDebug()<<"login thread id: "<< QThread::currentThreadId();
-    if(mServerStatus){
+
+    qDebug() << "login thread id: " << QThread::currentThreadId();
+
+    if ( mServerStatus ) {
         QMetaObject::invokeMethod( mServerMap.first().data(), "login", Q_ARG( QString, pUsername ), Q_ARG( QString, pPassword ) );
     }
 }
 
 void RocketChat::loadRecentHistory( QString pChannelId )
 {
-    if(mServerStatus){
+    if ( mServerStatus ) {
         QMetaObject::invokeMethod( mServerMap.first().data(), "loadRecentHistory", Q_ARG( QString, pChannelId ) );
     }
 }
@@ -110,18 +114,18 @@ bool RocketChat::isStorageReady()
 
 void RocketChat::forceVirtualKeyboardShow()
 {
-    QGuiApplication::inputMethod()->setVisible(true);
+    QGuiApplication::inputMethod()->setVisible( true );
 }
 
 void RocketChat::forceVirtualKeyboardHide()
 {
-    QGuiApplication::inputMethod()->setVisible(false);
+    QGuiApplication::inputMethod()->setVisible( false );
 }
 
-void RocketChat::setStatusBarColor(QString pColor)
+void RocketChat::setStatusBarColor( QString pColor )
 {
 #ifdef Q_OS_ANDROID
-    mAndroidStatusBarColor->setStatusBarColor(pColor);
+    mAndroidStatusBarColor->setStatusBarColor( pColor );
 #endif
 }
 
@@ -138,9 +142,11 @@ void RocketChat::resetChannelSwitchRequest()
 void RocketChat::channelViewReady()
 {
 #ifdef Q_OS_IOS
-    if(!mShareHelper->getPath().isEmpty()){
-        openIosFile(mShareHelper->getPath());
+
+    if ( !mShareHelper->getPath().isEmpty() ) {
+        openIosFile( mShareHelper->getPath() );
     }
+
 #endif
 }
 
@@ -154,25 +160,61 @@ void RocketChat::checkLoggedIn()
 
 }
 
-void RocketChat::getChannelDetails(QString pServerId, QString pChannelName)
+void RocketChat::getChannelDetails( QString pServerId, QString pChannelName )
 {
     Q_UNUSED( pServerId );
-    if(mServerStatus){
+
+    if ( mServerStatus ) {
         QMetaObject::invokeMethod( mServerMap.first().data(), "requestGetChannelDetails", Q_ARG( QString, pChannelName ) );
     }
 }
 
-void RocketChat::createVideoCall(QString pServerId, QString pChannelId)
+void RocketChat::createVideoCall( QString pServerId, QString pChannelId )
 {
     Q_UNUSED( pServerId );
-    QMetaObject::invokeMethod(mServerMap.first().data(), "createVideoCall", Q_ARG(QString, pChannelId));
+    QMetaObject::invokeMethod( mServerMap.first().data(), "createVideoCall", Q_ARG( QString, pChannelId ) );
+}
+
+bool RocketChat::newServerByDomain( QString domain )
+{
+    mDdpConnectionEstablished = false;
+    auto newServer = [ = ]() {
+        qDebug() << "terminated thread";
+        QString BaseUrl = domain;
+        QString ApiUri = "https://" + domain + "/api/v1";
+        channelModel.clear();
+        groupsModel.clear();
+        directmodel.clear();
+        QSharedPointer<RocketChatServerData> server( new RocketChatServerData( domain, BaseUrl, ApiUri, userModel, channelModel, groupsModel, directmodel, messagesModel ) );
+
+        emit offline();
+        //evil hack to avoid race condition I cannot find
+        mServerMap.clear();
+        QThread::currentThread()->msleep( 50 );
+        registerServer( server );
+    };
+
+    if ( mServerThread.isRunning() ) {
+        connect( &mServerThread, &QThread::finished, this, newServer );
+        //don´t ask, I dunno why this is needed but it works
+#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
+        mServerThread.quit();
+#endif
+
+        mServerThread.terminate();
+    } else {
+        newServer();
+    }
+
+    return 0;
 }
 
 //TODO: make asynchonous
 void RocketChat::getUserOfChannel( QString pServerId, QString pChannelId )
 {
     Q_UNUSED( pServerId );
-    if(mServerStatus){
+
+    if ( mServerStatus ) {
         QMetaObject::invokeMethod( mServerMap.first().data(), "requestUsersOfChannel", Q_ARG( QString, pChannelId ) );
     }
 }
@@ -181,21 +223,22 @@ void RocketChat::getUserOfChannel( QString pServerId, QString pChannelId )
 void RocketChat::openPrivateChannelWith( QString pServerId, QString pUsername )
 {
     Q_UNUSED( pServerId );
-    if(mServerStatus){
+
+    if ( mServerStatus ) {
         QMetaObject::invokeMethod( mServerMap.first().data(), "openPrivateChannelWith", Q_ARG( QString, pUsername ) );
     }
 }
 
 void RocketChat::getFileRessource( QString pUrl )
 {
-    if(mServerStatus){
+    if ( mServerStatus ) {
         QMetaObject::invokeMethod( mServerMap.first().data(), "getFileRessource", Q_ARG( QString, pUrl ), Q_ARG( QString, "temp" ) );
     }
 }
 
 void RocketChat::getFileRessource( QString pUrl, QString pType )
 {
-    if(mServerStatus){
+    if ( mServerStatus ) {
         QMetaObject::invokeMethod( mServerMap.first().data(), "getFileRessource", Q_ARG( QString, pUrl ), Q_ARG( QString, pType ) );
     }
 }
@@ -233,7 +276,8 @@ void RocketChat::uploadFile( QString pChannelId, QString pPath )
 void RocketChat::addUsersToChannel( QString pServerId, QString pChannelName, QString pUsernames )
 {
     Q_UNUSED( pServerId );
-    if(mServerStatus){
+
+    if ( mServerStatus ) {
         QStringList unserList = pUsernames.split( "," );
         QMetaObject::invokeMethod( mServerMap.first().data(), "addUsersToChannel", Q_ARG( QString, pChannelName ), Q_ARG( QStringList, unserList ) );
     }
@@ -243,7 +287,8 @@ void RocketChat::addUsersToChannel( QString pServerId, QString pChannelName, QSt
 void RocketChat::sendMessage( QString pServerId, QString pChannelId, QString pMessage )
 {
     Q_UNUSED( pServerId );
-    if(mServerStatus){
+
+    if ( mServerStatus ) {
         QSharedPointer<RocketChatServerData> server = mServerMap.first();
         QMetaObject::invokeMethod( mServerMap.first().data(), "sendMessage", Q_ARG( QString, pChannelId ), Q_ARG( QString, pMessage ) );
     }
@@ -275,7 +320,8 @@ void RocketChat::openFileExternally( QString pPath )
 void RocketChat::getSortOrderByCategory( QString pServerId, QString pType )
 {
     Q_UNUSED( pServerId );
-    if(mServerStatus){
+
+    if ( mServerStatus ) {
         QMetaObject::invokeMethod( mServerMap.first().data(), "requestChannelSortOrder", Q_ARG( QString, pType ) );
     }
 }
@@ -296,21 +342,21 @@ bool RocketChat::hasCameraPermission()
 
 QString RocketChat::getCleanString( QString pText )
 {
-    pText = Utils::replaceUnicodeEmojis(pText, mServerMap.first()->getEmojiRepo() );
+    pText = Utils::replaceUnicodeEmojis( pText, mServerMap.first()->getEmojiRepo() );
     pText = Utils::removeUtf8Emojis( pText );
     return pText;
 }
 
 void RocketChat::getAllChannels()
 {
-    if(mServerStatus){
+    if ( mServerStatus ) {
         QMetaObject::invokeMethod( mServerMap.first().data(), "requestAllChannels" );
     }
 }
 
 void RocketChat::uploadSharedFileToChannel( QString pChannelId )
 {
-    if(mServerStatus){
+    if ( mServerStatus ) {
         QMetaObject::invokeMethod( mServerMap.first().data(), "uploadFile", Q_ARG( QString, pChannelId ), Q_ARG( QString, mFileToShare ) );
     }
 }
@@ -319,7 +365,8 @@ void RocketChat::joinJitsiCall( QString pServer, QString pChannelIdm, QString pM
 {
     Q_UNUSED( pServer );
     Q_UNUSED( pMessageId );
-    if(mServerStatus){
+
+    if ( mServerStatus ) {
         QMetaObject::invokeMethod( mServerMap.first().data(), "joinJitsiCall", Q_ARG( QString, pChannelIdm ) );
     }
 }
@@ -328,9 +375,10 @@ void RocketChat::joinJitsiCall( QString pServer, QString pChannelIdm, QString pM
 QString RocketChat::getUsername( QString pServerId )
 {
     Q_UNUSED( pServerId );
-    if(mServerStatus){
+
+    if ( mServerStatus ) {
         return mServerMap.first()->getUsername();
-    }else{
+    } else {
         return "";
     }
 }
@@ -339,9 +387,10 @@ QString RocketChat::getUsername( QString pServerId )
 QString RocketChat::getPassword( QString pServerId )
 {
     Q_UNUSED( pServerId );
-    if(mServerStatus){
+
+    if ( mServerStatus ) {
         return mStorage->getPassword();
-    }else{
+    } else {
         return "";
     }
 }
@@ -362,7 +411,8 @@ void RocketChat::setCurrentChannel( QString pServerId, QString pCurrentChannel,
 {
     Q_UNUSED( pServerId );
     Q_UNUSED( pChannelName );
-    if(mServerStatus){
+
+    if ( mServerStatus ) {
         QMetaObject::invokeMethod( mServerMap.first().data(), "setCurrentChannel", Q_ARG( QString, pCurrentChannel ) );
     }
 }
@@ -384,7 +434,7 @@ QString RocketChat::getSetting( QString pKey )
 
 void RocketChat::callGalleryPicker( QString pChannelId )
 {
-    Q_UNUSED(pChannelId);
+    Q_UNUSED( pChannelId );
 #ifdef Q_OS_IOS
     mCurrentChannel = pChannelId;
 
@@ -397,7 +447,7 @@ void RocketChat::callGalleryPicker( QString pChannelId )
 
 void RocketChat::markChannelAsRead( QString pChannelId )
 {
-    if(mServerStatus){
+    if ( mServerStatus ) {
         QMetaObject::invokeMethod( mServerMap.first().data(), "markChannelAsRead", Q_ARG( QString, pChannelId ) );
     }
 }
@@ -417,7 +467,7 @@ void RocketChat::resetCurrentChannel()
 
 void RocketChat::getUserSuggestions( QString pTerm, QString pExceptions )
 {
-    if(mServerStatus){
+    if ( mServerStatus ) {
         QMetaObject::invokeMethod( mServerMap.first().data(), "getUserSuggestions", Q_ARG( QString, pTerm ), Q_ARG( QString, pExceptions ) );
     }
 }
@@ -425,7 +475,8 @@ void RocketChat::getUserSuggestions( QString pTerm, QString pExceptions )
 void RocketChat::getRoomInformation( QString pServerId, QString pChannelName )
 {
     Q_UNUSED( pServerId );
-    if(mServerStatus){
+
+    if ( mServerStatus ) {
         QMetaObject::invokeMethod( mServerMap.first().data(), "getRoomInformation", Q_ARG( QString, pChannelName ) );
     }
 }
@@ -433,7 +484,8 @@ void RocketChat::getRoomInformation( QString pServerId, QString pChannelName )
 void RocketChat::cancelUpload( QString pServerId, QString pFileId )
 {
     Q_UNUSED( pServerId );
-    if(mServerStatus){
+
+    if ( mServerStatus ) {
         QMetaObject::invokeMethod( mServerMap.first().data(), "cancelUpload", Q_ARG( QString, pFileId ) );
     }
 }
@@ -441,15 +493,17 @@ void RocketChat::cancelUpload( QString pServerId, QString pFileId )
 void RocketChat::logout( QString pServerId )
 {
     Q_UNUSED( pServerId );
-    if(mServerStatus){
-        QMetaObject::invokeMethod( mServerMap.first().data(), "logout");
+
+    if ( mServerStatus ) {
+        QMetaObject::invokeMethod( mServerMap.first().data(), "logout" );
     }
 }
 
 void RocketChat::createChannel( QString pServerId, QString pChannelName, QStringList pUsersNames, bool pReadonly )
 {
     Q_UNUSED( pServerId );
-    if(mServerStatus){
+
+    if ( mServerStatus ) {
         QMetaObject::invokeMethod( mServerMap.first().data(), "createChannel", Q_ARG( QString, pChannelName ), Q_ARG( QStringList, pUsersNames ), Q_ARG( bool, pReadonly ) );
     }
 }
@@ -457,17 +511,18 @@ void RocketChat::createChannel( QString pServerId, QString pChannelName, QString
 void RocketChat::createPrivateGroup( QString pServerId, QString pChannelName, QStringList pUsersNames, bool pReadonly )
 {
     Q_UNUSED( pServerId );
-    if(mServerStatus){
+
+    if ( mServerStatus ) {
         QMetaObject::invokeMethod( mServerMap.first().data(), "createPrivateGroup", Q_ARG( QString, pChannelName ), Q_ARG( QStringList, pUsersNames ), Q_ARG( bool, pReadonly ) );
     }
 }
 
 void RocketChat::registerServer( QSharedPointer<RocketChatServerData> pServer )
 {
-    pServer->moveToThread(&mServerThread);
+    pServer->moveToThread( &mServerThread );
     mServerMap[pServer->getServerId()] = pServer;
 
-    connect(&mServerThread,&QThread::started, this, &RocketChat::serverReadySlot, Qt::UniqueConnection);
+    connect( &mServerThread, &QThread::started, this, &RocketChat::serverReadySlot, Qt::UniqueConnection );
     connect( pServer.data(), &RocketChatServerData::readyToCheckForPendingNotification, this, &RocketChat::onServerSlotsReady, Qt::UniqueConnection );
 
     mServerThread.start();
@@ -479,15 +534,15 @@ void RocketChat::openIosFile( const QString &fileName )
     //QFile file(fileName);
 
     mFileToShare = fileName;
-    qDebug()<<"share file received...";
+    qDebug() << "share file received...";
     emit openShareDialog();
 }
 
-void RocketChat::openUrl(const QString url)
+void RocketChat::openUrl( const QString url )
 {
-    if(!QDesktopServices::openUrl(url)){
-         qDebug()<<"Jitsi meet could not be opened";
-         emit noJitsiMeetAvailable();
+    if ( !QDesktopServices::openUrl( url ) ) {
+        qDebug() << "Jitsi meet could not be opened";
+        emit noJitsiMeetAvailable();
     }
 }
 
@@ -503,35 +558,36 @@ void RocketChat::onLogout( QString pServerId )
     emit loggedOut( pServerId );
 }
 
-void RocketChat::onUnreadCountChanged(QString pServerId, uint pUnread)
+void RocketChat::onUnreadCountChanged( QString pServerId, uint pUnread )
 {
 
     mUnreadSum[pServerId] = pUnread;
 
-    qDebug()<<"onUnreadCountChanged";
+    qDebug() << "onUnreadCountChanged";
     uint number = 0;
 
-    if(mServerStatus){
-        for ( auto count: mUnreadSum ) {
+    if ( mServerStatus ) {
+        for ( auto count : mUnreadSum ) {
             number += count;
         }
-        qDebug()<<"set Unread Badges to:"<<number;
+
+        qDebug() << "set Unread Badges to:" << number;
 #ifdef Q_OS_ANDROID
 
         AndroidBadges::setNumber( number );
 #endif
 #ifdef Q_OS_IOS
-        IosBadges::setBadges(number);
+        IosBadges::setBadges( number );
 #endif
 
-     }
+    }
 
 }
 
-void RocketChat::onChannelSwitchRequest(QString server, QString rid, QString name, QString type, bool readonly)
+void RocketChat::onChannelSwitchRequest( QString server, QString rid, QString name, QString type, bool readonly )
 {
     //TODO: fix
-    emit channelSwitchRequest(server,rid,name,type, readonly);
+    emit channelSwitchRequest( server, rid, name, type, readonly );
     mChannelSwitchRequest["server"] = server;
     mChannelSwitchRequest["rid"] = rid;
     mChannelSwitchRequest["name"] = name;
@@ -559,14 +615,14 @@ void RocketChat::serverReadySlot()
     connect( pServer.data(), &RocketChatServerData::channelSwitchRequest, this, &RocketChat::onChannelSwitchRequest, Qt::UniqueConnection );
     connect( pServer.data(), &RocketChatServerData::onHashLoggedIn, this, &RocketChat::hashLoggedIn, Qt::UniqueConnection );
 
-    connect( pServer.data(), &RocketChatServerData::registerForPush, this, &RocketChat::registerForPush, Qt::UniqueConnection);
+    connect( pServer.data(), &RocketChatServerData::registerForPush, this, &RocketChat::registerForPush, Qt::UniqueConnection );
 
-    connect( pServer.data(), &RocketChatServerData::openUrl, this, &RocketChat::openUrl, Qt::UniqueConnection);
+    connect( pServer.data(), &RocketChatServerData::openUrl, this, &RocketChat::openUrl, Qt::UniqueConnection );
 
-    connect( pServer.data(), &RocketChatServerData::allChannelsReady, this, &RocketChat::onAllChannelsReceived, Qt::UniqueConnection);
-    connect( pServer.data(), &RocketChatServerData::usersReady, this, &RocketChat::channelUsersReady, Qt::UniqueConnection);
-    connect( pServer.data(), &RocketChatServerData::channelDetailsReady, this, &RocketChat::channelDetailsReady, Qt::UniqueConnection);
-    connect( pServer.data(), &RocketChatServerData::unreadCountChanged, this, &RocketChat::onUnreadCountChanged, Qt::UniqueConnection);
+    connect( pServer.data(), &RocketChatServerData::allChannelsReady, this, &RocketChat::onAllChannelsReceived, Qt::UniqueConnection );
+    connect( pServer.data(), &RocketChatServerData::usersReady, this, &RocketChat::channelUsersReady, Qt::UniqueConnection );
+    connect( pServer.data(), &RocketChatServerData::channelDetailsReady, this, &RocketChat::channelDetailsReady, Qt::UniqueConnection );
+    connect( pServer.data(), &RocketChatServerData::unreadCountChanged, this, &RocketChat::onUnreadCountChanged, Qt::UniqueConnection );
 
     connect( &mNetworkConfiguration, &QNetworkConfigurationManager::onlineStateChanged, this, &RocketChat::onOnlineStateChanged, Qt::UniqueConnection );
     QMetaObject::invokeMethod( mServerMap.first().data(), "init" );
@@ -604,7 +660,7 @@ void RocketChat::openFileNameReady( QString pFile )
 
     if ( pFile == "null" ) {
         emit error( "invalid file information" );
-    } else if ( !pFile.isEmpty() && mServerStatus) {
+    } else if ( !pFile.isEmpty() && mServerStatus ) {
         QMetaObject::invokeMethod( mServerMap.first().data() , "uploadFile", Q_ARG( QString, mCurrentChannel ), Q_ARG( QString, pFile ) );
     }
 }
@@ -612,21 +668,21 @@ void RocketChat::openFileNameReady( QString pFile )
 void RocketChat::onKeyboardVisiblityChanged()
 {
     QRectF keyBoardRect = mInputMethod->keyboardRectangle();
-    float height = floor(keyBoardRect.height()/2)-5;
-	bool visible = mInputMethod->isVisible();
-    emit keyboardVisibilityChanged(visible, height);
+    float height = floor( keyBoardRect.height() / 2 ) - 5;
+    bool visible = mInputMethod->isVisible();
+    emit keyboardVisibilityChanged( visible, height );
 }
 
-void RocketChat::onEmojisReady(QVariantList pEmojiList)
+void RocketChat::onEmojisReady( QVariantList pEmojiList )
 {
     mEmojisReady = true;
-    emit emojisReady(pEmojiList);
+    emit emojisReady( pEmojiList );
 }
 
 //used only for share Dialog
-void RocketChat::onAllChannelsReceived(QVariantList pChannels)
+void RocketChat::onAllChannelsReceived( QVariantList pChannels )
 {
-    emit allChannelsReceived(pChannels);
+    emit allChannelsReceived( pChannels );
 }
 
 void RocketChat::onServerSlotsReady()
@@ -660,7 +716,8 @@ void RocketChat::onOnlineStateChanged( bool pOnline )
 {
     qDebug() << "stat changed" << pOnline;
     connect( &mNetworkConfiguration, &QNetworkConfigurationManager::onlineStateChanged, this, &RocketChat::onOnlineStateChanged, Qt::UniqueConnection );
-    if(mServerStatus){
+
+    if ( mServerStatus ) {
         if ( pOnline ) {
 
             for ( auto server : mServerMap ) {
@@ -678,7 +735,7 @@ void RocketChat::onOnlineStateChanged( bool pOnline )
 
 void RocketChat::onApplicationStateChanged( Qt::ApplicationState pState )
 {
-    if ( pState == Qt::ApplicationActive &&mServerStatus ) {
+    if ( pState == Qt::ApplicationActive && mServerStatus ) {
         QDateTime date;
         qDebug() << "application changed to active";
         qDebug() << "time: " << date.currentDateTime();
@@ -690,19 +747,21 @@ void RocketChat::onApplicationStateChanged( Qt::ApplicationState pState )
 
         if ( mInitialized && mNetworkConfiguration.isOnline() ) {
             qDebug() << "network connection active";
+
             for ( auto server : mServerMap ) {
 
-                    //check if websocket connection is still alive, and if DDP is timedout
-                    QMetaObject::invokeMethod(server.data(), "onStateChanged", Q_ARG(Qt::ApplicationState, pState ));   
+                //check if websocket connection is still alive, and if DDP is timedout
+                QMetaObject::invokeMethod( server.data(), "onStateChanged", Q_ARG( Qt::ApplicationState, pState ) );
             }
         } else {
             mInitialized = 1;
         }
-    }else if(((pState == Qt::ApplicationInactive)||pState == Qt::ApplicationSuspended) &&mServerStatus){
-        qDebug()<<"away";
-        if(mNetworkConfiguration.isOnline()){
+    } else if ( ( ( pState == Qt::ApplicationInactive ) || pState == Qt::ApplicationSuspended ) && mServerStatus ) {
+        qDebug() << "away";
+
+        if ( mNetworkConfiguration.isOnline() ) {
             for ( auto server : mServerMap ) {
-                QMetaObject::invokeMethod( server.data(), "setUserPresenceStatus", Q_ARG(int,2) );
+                QMetaObject::invokeMethod( server.data(), "setUserPresenceStatus", Q_ARG( int, 2 ) );
             }
         }
     }
diff --git a/rocketchat.h b/rocketchat.h
index d7355f3bdf7e25eaf4ca3c7f7332a035382f853c..e28e319c86264d13bf1c6abcbfe4dc03e1c8a879 100755
--- a/rocketchat.h
+++ b/rocketchat.h
@@ -44,12 +44,12 @@ class RocketChat : public QObject
 {
         Q_OBJECT
     public:
-        RocketChat( QGuiApplication *mApp );
+        RocketChat( QGuiApplication *mApp, ChannelModel &channelModel,ChannelModel &groupsModel,ChannelModel &directmodel, MessagesModel &messagesModel,UserModel &userModel );
         ~RocketChat();
 
         Q_INVOKABLE void uploadFile( QString pChannelId, QString pPath );
         Q_INVOKABLE void uploadVideo( QString pChannelId, QString pPath );
-
+        Q_INVOKABLE bool newServerByDomain( QString pChannelId );
         Q_INVOKABLE bool getDdpConnectionEstablished() const;
 
         //TODO: should be moved to RocketChatServer
@@ -115,6 +115,7 @@ class RocketChat : public QObject
 
         Q_INVOKABLE void createVideoCall(QString pServerId, QString pChannelId);
 
+
         void channelsList( QString pFilter, QString pChannelType, QString pSort );
         void deleteFileMessage( QString pFileID );
         void ufsCreate( QString pFilename, int pSize, QString pMime, QString pRid );
@@ -193,6 +194,11 @@ class RocketChat : public QObject
         void onAllChannelsReceived(QVariantList pChannels);
 
         void onServerSlotsReady();
+        ChannelModel &channelModel;
+        ChannelModel &groupsModel;
+        ChannelModel &directmodel;
+        UserModel &userModel;
+        MessagesModel &messagesModel;
 
     signals:
 
diff --git a/rocketchatserver.cpp b/rocketchatserver.cpp
index 4af1b7c879226fd7813ee05c4ca3768042a2f9cc..a5ae1c4c15eff0cb14b6f4e2b1ff89cea66fd44c 100755
--- a/rocketchatserver.cpp
+++ b/rocketchatserver.cpp
@@ -31,21 +31,21 @@ RocketChatServerData::RocketChatServerData( QString pId,  QString pBaseUrl,
             }
         }
     };
+    mFileService = new FileService( this );
+    mEmojiService = new EmojiService( this, mFileService, mStorage );
+    setRestApi( new RestApi(this, "https://" + mBaseUrl, mApiUri ) );
 }
 
 void RocketChatServerData::init()
 {
-    mDdpApi = new MeteorDDP( mBaseUrl );
-    setRestApi( new RestApi( "https://" + mBaseUrl, mApiUri ) );
+    mDdpApi = new MeteorDDP(this, mBaseUrl );
+
     mRestApi->moveToThread(QThread::currentThread());
     mDdpApi->moveToThread(QThread::currentThread());
     mUsername = mStorage->getUserName();
 
     mChannels = new ChannelRepository(channelsModel, channelsModel, groupsModel,mMessagesModel);
 
-    mFileService = new FileService( this );
-    mEmojiService = new EmojiService( this, mFileService, mStorage );
-
     connect( mDdpApi, &MeteorDDP::messageReceived, this, &RocketChatServerData::onDDPMessageReceived, Qt::UniqueConnection );
     connect( mDdpApi, &MeteorDDP::ddpConnected, this, &RocketChatServerData::onDDPConnected, Qt::UniqueConnection );
     qDebug() << "loaded channel list from db";
@@ -894,24 +894,6 @@ void RocketChatServerData::setConnectionState( const ConnectionState &pValue )
     mConnectionState = pValue;
 }
 
-RocketChatServerData::~RocketChatServerData()
-{
-    disconnect( mDdpApi, &MeteorDDP::messageReceived, this, &RocketChatServerData::onDDPMessageReceived );
-    disconnect( mDdpApi, &MeteorDDP::ddpConnected, this, &RocketChatServerData::onDDPConnected );
-    disconnect( channelService, &RocketChatChannelService::channelsLoaded, this, &RocketChatServerData::onChannelsLoaded );
-    disconnect( channelService, &RocketChatChannelService::usersLoaded, this, &RocketChatServerData::onUsersLoaded );
-
-    qDebug()<<"serverThread "<<QThread::currentThreadId();
-
-    mDdpApi->deleteLater();
-    mRestApi->deleteLater();
-    mMessageService->deleteLater();
-    channelService->deleteLater();
-    mEmojiRepo->deleteLater();
-    delete mFileService;
-    delete mEmojiService;
-}
-
 QString RocketChatServerData::getCurrentChannel() const
 {
     return mCurrentChannel;
diff --git a/rocketchatserver.h b/rocketchatserver.h
index accdb62b0fd9de02088ab43804cb0f1ef8eb4cfe..1395537ddeea199fc95d30c4855d9b0a5acf3924 100755
--- a/rocketchatserver.h
+++ b/rocketchatserver.h
@@ -174,7 +174,6 @@ public:
         QJsonObject formatMessageTime( QJsonObject pJsonObject );
         bool initialised = 0;
         ConnectionState getConnectionState() const;
-        ~RocketChatServerData();
 
         QString getCurrentChannel() const;
 
@@ -217,7 +216,7 @@ protected:
         EmojiService *mEmojiService;
         QVariantList mEmojis;
         QMimeDatabase mMimeDb;
-        FileService *mFileService;
+        FileService *mFileService = nullptr;
         QNetworkConfigurationManager mNetworkConfiguration;
         QHash<QString, bool> mDownloadsInProgress;
         void getServerSettings(void);
diff --git a/websocket/linuxwebsocket/websocketlinux.cpp b/websocket/linuxwebsocket/websocketlinux.cpp
index bd9b7cfd689962a9e214ab1cc5a891b86165b586..73d0e0b1b5f49b04c135d75705623e20a3a1aa81 100755
--- a/websocket/linuxwebsocket/websocketlinux.cpp
+++ b/websocket/linuxwebsocket/websocketlinux.cpp
@@ -3,7 +3,7 @@
 #include "websocketlinux.h"
 #include "websocketabstract.h"
 
-websocketLinux::websocketLinux()
+websocketLinux::websocketLinux(QObject *parent):WebsocketAbstract(parent),mWebsocket("rocket.chat.mobile",QWebSocketProtocol::VersionLatest,this)
 {
     connect(&mWebsocket,&QWebSocket::connected,this,&websocketLinux::connected, Qt::UniqueConnection);
     connect(&mWebsocket,&QWebSocket::textMessageReceived,this,&websocketLinux::received, Qt::UniqueConnection);
@@ -12,15 +12,6 @@ websocketLinux::websocketLinux()
     connect(&mWebsocket, &QWebSocket::stateChanged, this,&websocketLinux::onStatusChanged, Qt::UniqueConnection );
 }
 
-websocketLinux::~websocketLinux()
-{
-    qDebug()<<"destroy websocket linux";
-    disconnect(&mWebsocket,&QWebSocket::connected,this,&websocketLinux::connected);
-    disconnect(&mWebsocket,&QWebSocket::textMessageReceived,this,&websocketLinux::textMessageReceived);
-    disconnect(&mWebsocket,&QWebSocket::disconnected,this,&websocketLinux::closed);
-    mWebsocket.deleteLater();
-}
-
 void websocketLinux::open(QUrl url)
 {
     qDebug() << "open url";
diff --git a/websocket/linuxwebsocket/websocketlinux.h b/websocket/linuxwebsocket/websocketlinux.h
index 28d153976bb628cb73bb8254924cd9a0ebe0f07b..9914f5d4621cb4209a1f6bc01e25518acd343543 100755
--- a/websocket/linuxwebsocket/websocketlinux.h
+++ b/websocket/linuxwebsocket/websocketlinux.h
@@ -10,9 +10,7 @@
 class websocketLinux:public WebsocketAbstract
 {
 public:
-    websocketLinux();
-    ~websocketLinux();
-
+    websocketLinux(QObject *parent);
     virtual void open(QUrl) override;
     virtual void close() override;
     virtual void sendTextMessage(QString) override;
diff --git a/websocket/websocket.cpp b/websocket/websocket.cpp
index 92a08cc39580ddc64dd127404ce52c2e71fecaf1..9ce011abdd94c15b2c38912b463c393f1dd188db 100755
--- a/websocket/websocket.cpp
+++ b/websocket/websocket.cpp
@@ -9,14 +9,14 @@
     #include "websocketlinux.h"
 #endif
 
-Websocket::Websocket()
+Websocket::Websocket(QObject *parent):WebsocketAbstract(parent)
 {
     qRegisterMetaType<QAbstractSocket::SocketState>("QAbstractSocket::SocketState");
 #ifdef Q_OS_WINRT
    qDebug() << "Windows RT websocket instantiated";
    mWebsocketInstance = new WinRTWebsocket;
 #else
-    mWebsocketInstance = new websocketLinux;
+    mWebsocketInstance = new websocketLinux(this);
 #endif
     connect(mWebsocketInstance,&WebsocketAbstract::connected,this,&Websocket::connected, Qt::UniqueConnection);
     connect(mWebsocketInstance,&WebsocketAbstract::textMessageReceived,this,&Websocket::textMessageReceived, Qt::UniqueConnection);
diff --git a/websocket/websocket.h b/websocket/websocket.h
index 6b7da6b433124fc58a352b75bbe41cc1cb3da3bc..08d1ee42c7ab729515c526a724abb94c71d0dac6 100755
--- a/websocket/websocket.h
+++ b/websocket/websocket.h
@@ -9,7 +9,7 @@
 class Websocket: public WebsocketAbstract
 {
 public:
-    Websocket();
+    Websocket(QObject *parent);
 
     virtual void open(QUrl) override;
     virtual void close(void) override;
diff --git a/websocket/websocketabstract.cpp b/websocket/websocketabstract.cpp
index 9f02b2a8cff1833a2be189463233fa7addb13e5f..e34222e6d902466c33234b1592bee9e3f1959946 100755
--- a/websocket/websocketabstract.cpp
+++ b/websocket/websocketabstract.cpp
@@ -1,6 +1,6 @@
 #include "websocketabstract.h"
 
-WebsocketAbstract::WebsocketAbstract()
+WebsocketAbstract::WebsocketAbstract(QObject *parent):QObject(parent)
 {
 
 }
diff --git a/websocket/websocketabstract.h b/websocket/websocketabstract.h
index 9ed5e4ed0b33517dee3c9c28a87d41c47b724fb2..d4deb927984428e79cd9a2753d9323e09f95d802 100755
--- a/websocket/websocketabstract.h
+++ b/websocket/websocketabstract.h
@@ -11,7 +11,7 @@ class WebsocketAbstract:public QObject
 {
     Q_OBJECT
 public:
-    WebsocketAbstract();
+    WebsocketAbstract(QObject *parent);
 
     virtual void open(QUrl) = 0;
     virtual void close(void) = 0;