Fixed disconnect problems and added exception handling