Refactoring and commenting of conenction
working verison of connection