refactor disconnection handling
fix pep8