added logging and extra connection handling