improved error checking and log messaging