Added more comments and more logging.