Add more logging.
Move some code around.