added logging and configuration option to reconnection