Added connection handling