adding disconnect checks and bugfixes
fixed merge conflicts