Transfered a part of the code into functions to be easier to make a transition to the new type of <conn>