Merged with Sanae's rrc_inference_with_export branch.