Updated to fix alert handling and add logging.