fix bugs and disconnect handling