Updated to include better logging.