Connection: misc code rearranging