[#30621] Fix batch issues, metadata issues and improve code quality.
Thanks Elin Waring and Mark Dexter.