moved logging call around