Optimize traces and add variable logging.