added some defensive programming for logging