Reorganize and add logging.