bug fixes related to connection handling