Fixed disconnect handling and added safechecks on socket table entries