added logging, added timeout and failure handlingin actual connection routine