Kill threads in «disconnect».
Make debug function configurable.