updated code to allow for more debug logging.